<?php


namespace App\Service\Http;


use GuzzleHttp\Client;

class Guzzle implements HttpInterface
{

    /**
     *
     * @var \GuzzleHttp\Client
     */
    private $client;

    public function __construct()
    {

        $client = new Client();

        $this->client = $client;

    }



    /*
     * $res=$http->get('http://192.168.70.128/demo/test/123.php',[
     *     'test'=>123,
     *      'uu'=>456
     *  ],[
     *      'headers'=>[
     *          'test'=>456
     *      ]
     *  ]);
     *
     *
     */


    /**
     *
     * Create by Peter
     * 2019/09/18 14:19:48
     * Email:904801074@qq.com
     * @param $url
     * @param array $query
     * @param array $options
     * @return string
     */
    public function get($url, $query = [], $options = [])
    {
        // TODO: Implement get() method.

        $options_=[];

        if($query) $options_=['query' => $query];

        if ($options) $options_ = array_merge($options_, $options);

        return $this->client->get($url,$options_)->getBody()->getContents();
    }

    public function post($url, $form_params = [], $options = [])
    {
        // TODO: Implement post() method.

        $options_=[];

        if($form_params) $options_=['form_params' => $form_params];

        if ($options) $options_ = array_merge($options_, $options);

        return $this->client->post($url,$options_)->getBody()->getContents();
    }
}
